/**
 Copyright (C) 2013 Yuyao Liang

 This source code is release under the BSD License.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.

 Created on Oct 25, 2013 11:34:16 AM
 */
package com.googlecode.backtest.rule;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.googlecode.backtest.dataset.manager.DataReadyEventListener;

/**
 * @author lianyuy
 * 
 */
public abstract class BackTestAlgorithm<T, S> implements
		IBackTestAlgorithm<T, S>, DataReadyEventListener {
	protected List<T> dataset = null;
	protected S parameter = null;
	protected T result = null;
	protected String _ID;
	protected List<String> data_ids;

	protected BackTestAlgorithm(String id, List<String> data_ids, S parameter) {
		_ID = id;
		this.data_ids = data_ids;
		this.parameter = parameter;
	}

	public BackTestAlgorithm() {
		Long uuid = UUID.randomUUID().getMostSignificantBits();
		_ID = Long.toHexString(uuid);
		data_ids = new ArrayList<String>();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.GUIDable#getGUID()
	 */
	@Override
	public String getGUID() {
		return _ID;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.googlecode.backtest.rule.IBackTestAlgorithm#isValid(java.lang.Object)
	 */
	@Override
	public boolean isValid() {
		return dataset != null && dataset.size() > 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.googlecode.backtest.rule.IBackTestAlgorithm#getResult()
	 */
	@Override
	public T getResult() {
		return result;
	}

}
